﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace while语句01
{
    class Program
    {
        static void Main(string[] args)
        {
            //int a = 1;
            //int b = 10;

            ////"当"型循环
            //while (a < b)
            //{//当a<b的时候，会执行a++
            //    a++;
            //}
            //Console.WriteLine("a的值为{0}", a);

            // 练习1：打印1-100之内的所有偶数/奇数
            //int index = 0;
            //while (index <= 99)
            //{
            //    index++;
            //    if (index % 2 != 0)
            //    {
            //        Console.WriteLine(index);
            //    }
            //}

            //int index = 1;
            //while (index <= 100)
            //{
            //    if (index % 2 == 0)
            //    {
            //        Console.WriteLine(index);
            //    }
            //    index++;
            //}


            // 练习2：打印1-100所有奇/偶数的和
            int index = 1;
            int sum = 0;
            while (index < 101)
            {
                if (index % 2 != 1)
                {
                    sum += index;
                    //c
                }
                index++;
                //b
            }
            Console.WriteLine("1-100所有奇数的和 = {0}", sum);
        }
    }
}
